package com.atguigu.gulimall.cart.entry.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * 整个购物车
 */
public class CartVo {
    private List<CartItemVo> itemVos;

    private Integer countNum;//商品数量

    private Integer countType;//商品类型数量

    private BigDecimal totalAmount;//商品总价

    private BigDecimal reduce = new BigDecimal(0);//减免价格

    public List<CartItemVo> getItemVos() {
        return itemVos;
    }

    public void setItemVos(List<CartItemVo> itemVos) {
        this.itemVos = itemVos;
    }

    /**
     * 计算总数量
     * @return
     */
    public Integer getCountNum() {
        countNum = 0;
        if (itemVos != null && itemVos.size() > 0){
            for (CartItemVo itemVo : itemVos) {
                countNum += itemVo.getCount();
            }
        }
        return countNum;
    }


    public Integer getCountType() {
//        countType = 0;
//        if (itemVos != null && itemVos.size() > 0){
//            for (CartItemVo itemVo : itemVos) {
//                countNum += 1;
//            }
//        }
        return itemVos.size();
    }


    public BigDecimal getTotalAmount() {
        BigDecimal bigDecimal = new BigDecimal(0);
        //计算购物项总价
        if (itemVos != null && itemVos.size() > 0){
            for (CartItemVo itemVo : itemVos) {
                //如果被选中的计算价格
                if (itemVo.getCheck()){
                    bigDecimal = bigDecimal.add(itemVo.getTotlePrice());
                }
            }
        }

        //减去优惠总价
        BigDecimal subtract = bigDecimal.subtract(getReduce());

        return subtract;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
